package com.thinkfit.jy.activity;

import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.common.lib.bean.VideoBean;
import com.common.lib.bean.VideoSectionBean;
import com.common.lib.constant.Constants;
import com.common.lib.constant.EventBusEvent;
import com.common.lib.manager.DataManager;
import com.common.lib.utils.BaseUtils;
import com.thinkfit.jy.R;
import com.thinkfit.jy.contract.VideoCourseDetailContract;
import com.thinkfit.jy.dialog.AppPopupWindow;
import com.thinkfit.jy.presenter.VideoCourseDetailPresenter;
import com.thinkfit.jy.serialport.SerialPortManager;
import com.thinkfit.jy.serialport.SportType;
import com.thinkfit.jy.utils.BluetoothOrder;
import com.thinkfit.jy.utils.DeviceTypeUtils;
import com.thinkfit.jy.utils.EquipmentInfoUtils;
import com.thinkfit.jy.utils.FastBlurUtility;
import com.thinkfit.jy.utils.MotionDataUtils;
import com.thinkfit.jy.utils.SafetyLockViewUtils;
import com.thinkfit.jy.utils.ShowSpeedViewUtils;
import com.thinkfit.jy.utils.SportsDataUtils;
import com.thinkfit.jy.utils.SportsStatusBarViewUtils;
import com.thinkfit.jy.utils.ThemeUtils;
import com.thinkfit.jy.view.MultiProgressView;
import com.xiao.nicevideoplayer.NiceVideoPlayerManager;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import xyz.doikki.videocontroller.StandardVideoController;
import xyz.doikki.videocontroller.component.GestureView;
import xyz.doikki.videocontroller.component.VodControlView;
import xyz.doikki.videoplayer.player.VideoView;

/**
 * 视频课程运动界面
 */
public class VideoCourseDetailActivity extends MainActivity implements VideoCourseDetailContract.View {
    private int mDuration;
    private int mLastTime;

    private VideoBean mVideo;
//    private TxVideoPlayerController mController;
    private StandardVideoController mController;
    private MultiProgressView mMultiProgressView;
    private VideoView mNiceVideoPlayer;

    private ArrayList<VideoSectionBean> vburst;

    private boolean mIsInit;
    private int mMainStyle,vType;

    ConstraintLayout clHome;

    Disposable concealButtonDisposable;

    int countDownConcealButton = 5;

    RelativeLayout rlMain;

    @Override
    protected int getLayoutId() {
//        mMainStyle = DataManager.Companion.getInstance().getMainStyle();
//        return mMainStyle == 3 ? R.layout.activity_video_course_detail_xm :
        return  R.layout.activity_video_course_detail;
    }

    public void init() {
        mVideo = (VideoBean) getIntent().getSerializableExtra(Constants.BUNDLE_EXTRA);
        vType = getIntent().getIntExtra(Constants.BUNDLE_EXTRA_2,1);
        if(DeviceTypeUtils.connectDeviceType() == 0){
            BluetoothOrder.getInstance().setSportType(SportType.VIDEO);
        }else {
            SerialPortManager.getInstance().setSportType(SportType.VIDEO, mVideo.getVideoId());
        }
        rlMain = findViewById(R.id.rootView);
        ((VideoCourseDetailContract.Presenter) getPresenter()).getVideoCourseDetail(mVideo.getVideoId(),vType);
        SportsDataUtils.getInstance().setSportType(SportType.VIDEO);
        showVideo();

        mDuration = 0;
        mLastTime = -1;
        mIsInit = true;

        showStartBtn(MotionDataUtils.getInstance().isRun());
//        getNiceVideoPlayer().continueFromLastPosition(false);

        clHome = findViewById(R.id.cl_home);
    }

    public void setSlops(){
        if (EquipmentInfoUtils.getInstance().getResistance() > 0) {
            int resistance = EquipmentInfoUtils.getInstance().getResistance();
            int i = resistance / 4;
            setText(R.id.tvSlop1, resistance+"");
            setText(R.id.tvSlop2, (i*2)+"");
            setText(R.id.tvSlop3, i+"");
            setText(R.id.tvSlop4, "1");
        }else {
            setText(R.id.tvSlop1, "-");
            setText(R.id.tvSlop2, "-");
            setText(R.id.tvSlop3, "-");
            setText(R.id.tvSlop4, "-");
        }
    }

    public void showUserInfo() {

    }

    private void showVideo() {
//        getNiceVideoPlayer().setPlayerType(NiceVideoPlayer.TYPE_NATIVE);//这个没办法设置播放速度
//        getNiceVideoPlayer().setPlayerType(NiceVideoPlayer.TYPE_IJK);

        mController = new StandardVideoController(this);
//        mController.setTitle("");
        getNiceVideoPlayer().setVideoController(mController);
        GestureView gestureView = new GestureView(this);
        VodControlView vodControlView = new VodControlView(this);//点播控制条
        //是否显示底部进度条。默认显示
        vodControlView.showBottomProgress(false);
        mController.addControlComponent(vodControlView);
        mController.addControlComponent(gestureView);
        //竖屏也开启手势操作，默认关闭
        mController.setEnableInNormal(true);
        //滑动调节亮度，音量，进度，默认开启
        mController.setGestureEnabled(true);

        if (!TextUtils.isEmpty(mVideo.getUrl())) {
            getNiceVideoPlayer().setUrl(mVideo.getUrl(), null);
//            getNiceVideoPlayer().setUrl("http" + Objects.requireNonNull(mVideo.getUrl()).substring(5), null);
//            getNiceVideoPlayer().setUp("http" + Objects.requireNonNull(mVideo.getUrl()).substring(5), null);
        }
//        BaseUtils.StaticParams.loadImage(this, 0, mVideo.getCover(), findViewById(R.id.iv));
//        mController.setVisibility(View.GONE);
    }

    @NonNull
    @Override
    protected VideoCourseDetailContract.Presenter onCreatePresenter() {
        return new VideoCourseDetailPresenter(this);
    }

    boolean mIsStart = false;

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rootView:
                clHome.setVisibility(View.VISIBLE);
                setViewVisible(R.id.line);
                concealButton();
                break;
            case R.id.llStart:
                if (SerialPortManager.getInstance().isConnected()||BluetoothOrder.getInstance().isConnect()) {
                    super.onClick(v);
                } else {
                    System.out.println("ddddddddddddddddddddddd  mIsStart : "+mIsStart);
                    if (!mIsStart) {
                        getNiceVideoPlayer().start();
                        showStartBtn(true);
                        mIsStart = true;
                        concealButton();
                    } else {
//                        getNiceVideoPlayer().continueFromLastPosition(true);
                        getNiceVideoPlayer().pause();
                        showStartBtn(false);
                        mIsStart = false;
                        time = 1;
                    }
                }
                break;
            case R.id.ivBack:
//                if(DeviceTypeUtils.connectDeviceType() == 0){
//                    if(!BluetoothOrder.getInstance().isRun()){
//                        finish();
//                        return;
//                    }
//                }else {
//                    if (!SerialPortManager.getInstance().isRun()){
//                        finish();
//                        return;
//                    }
//                }


                if (DataManager.Companion.getInstance().getMainStyle() == 3) {
                    DataManager.Companion.getInstance().setObject(FastBlurUtility.getBlurBackgroundDrawer(this));
                }
                Intent intent = new Intent(this, DialogActivity.class);
                intent.putExtra(Constants.BUNDLE_EXTRA, DialogActivity.END_SPORT_BACK);
                startActivity(intent);
                break;
            case R.id.ivHome:
//                if (!SerialPortManager.getInstance().isRun()) {
//                    toHomeActivity();
//                    return;
//                }
                if (DataManager.Companion.getInstance().getMainStyle() == 3) {
                    DataManager.Companion.getInstance().setObject(FastBlurUtility.getBlurBackgroundDrawer(this));
                }
                intent = new Intent(this, DialogActivity.class);
                intent.putExtra(Constants.BUNDLE_EXTRA, DialogActivity.END_SPORT_TO_HOME);
                startActivity(intent);
                break;
            case R.id.llSlop1:
//                resetSlopBtn(1);
                if(!DeviceTypeUtils.isConnect()){
                    showToast(R.string.app_device_connect);
                    return;
                }
                if(getTextById(R.id.tvSlop1).equals("-")){
                    return;
                }
                setEqSlop(Integer.parseInt(getTextById(R.id.tvSlop1)));
                break;
            case R.id.llSlop2:
//                resetSlopBtn(2);
                if(!DeviceTypeUtils.isConnect()){
                    showToast(R.string.app_device_connect);
                    return;
                }
                if(getTextById(R.id.tvSlop2).equals("-")){
                    return;
                }
                setEqSlop(Integer.parseInt(getTextById(R.id.tvSlop2)));
                break;
            case R.id.llSlop3:
//                resetSlopBtn(3);
                if(!DeviceTypeUtils.isConnect()){
                    showToast(R.string.app_device_connect);
                    return;
                }
                if(getTextById(R.id.tvSlop3).equals("-")){
                    return;
                }
                setEqSlop(Integer.parseInt(getTextById(R.id.tvSlop3)));
                break;
            case R.id.llSlop4:
//                resetSlopBtn(4);
                if(!DeviceTypeUtils.isConnect()){
                    showToast(R.string.app_device_connect);
                    return;
                }
                if(getTextById(R.id.tvSlop4).equals("-")){
                    return;
                }
                setEqSlop(Integer.parseInt(getTextById(R.id.tvSlop4)));
                break;
            case R.id.llSpeed1:
//                resetSpeedBtn(1);
                if(!DeviceTypeUtils.isConnect()){
                    showToast(R.string.app_device_connect);
                    return;
                }
                if(getTextById(R.id.tvSpeed1).equals("-")){
                    return;
                }
                setEqSpeed(Integer.parseInt(getTextById(R.id.tvSpeed1)));

                break;
            case R.id.llSpeed2:
//                resetSpeedBtn(2);
                if(!DeviceTypeUtils.isConnect()){
                    showToast(R.string.app_device_connect);
                    return;
                }
                if(getTextById(R.id.tvSpeed2).equals("-")){
                    return;
                }
                setEqSpeed(Integer.parseInt(getTextById(R.id.tvSpeed2)));
                break;
            case R.id.llSpeed3:
//                resetSpeedBtn(3);
                if(!DeviceTypeUtils.isConnect()){
                    showToast(R.string.app_device_connect);
                    return;
                }
                if(getTextById(R.id.tvSpeed3).equals("-")){
                    return;
                }
                setEqSpeed(Integer.parseInt(getTextById(R.id.tvSpeed3)));
                break;
            case R.id.llSpeed4:
//                resetSpeedBtn(4);
                if(!DeviceTypeUtils.isConnect()){
                    showToast(R.string.app_device_connect);
                    return;
                }
                if(getTextById(R.id.tvSpeed4).equals("-")){
                    return;
                }
                setEqSpeed(Integer.parseInt(getTextById(R.id.tvSpeed4)));
                break;
            case R.id.ivSpeedAdd:
                resetSpeed(true);
                break;
            case R.id.ivSpeedMinus:
                resetSpeed(false);
                break;
            case R.id.ivSlopAdd:
                resetSlop(true);
                break;
            case R.id.ivSlopMinus:
                resetSlop(false);
                break;

            default:
                super.onClick(v);
                break;
        }
    }


    public ArrayList<AppUtils.AppInfo> getAppList(){
        ArrayList<AppUtils.AppInfo> list1 = new ArrayList<>();
        PackageManager pm = this.getPackageManager();
        List<PackageInfo> packages = pm.getInstalledPackages(0);
        int size = packages.size();
        for (int i = 0; i < size; i++) {
            PackageInfo packageInfo = packages.get(i);
            if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) > 0 ||
                    packageInfo.packageName.equals(this.getPackageName())) {
                continue;
            }
            list1.add(new AppUtils.AppInfo(
                    packageInfo.packageName,
                    packageInfo.applicationInfo.loadLabel(pm).toString(),
                    packageInfo.applicationInfo.loadIcon(pm),
                    "",
                    packageInfo.versionName,
                    packageInfo.versionCode,
                    false
            ));
        }
        return list1;
    }

    /**
     * 设置速度
     * @param speed
     */
    public void setEqSpeed(int speed){
        if(DeviceTypeUtils.connectDeviceType() == 0){
            BluetoothOrder.getInstance().setNowelAndSlope(speed, MotionDataUtils.getInstance().getCurrentInfo().slop);
        }else {
            SerialPortManager.getInstance().setSpeedSlop(speed, MotionDataUtils.getInstance().getCurrentInfo().slop);
        }
    }

    /**
     * 设置阻力
     * @param slop
     */
    public void setEqSlop(int slop){
        if(DeviceTypeUtils.connectDeviceType() == 0){
            if (DeviceTypeUtils.TREADMILL.equals(MotionDataUtils.mCurrentDeviceType)) {
                BluetoothOrder.getInstance().setNowelAndSlope(MotionDataUtils.getInstance().getCurrentInfo().speed, slop);
            } else {
                BluetoothOrder.getInstance().setNowelAndSlope(slop, MotionDataUtils.getInstance().getCurrentInfo().slop);
            }
        }else {
            if (DeviceTypeUtils.TREADMILL.equals(MotionDataUtils.mCurrentDeviceType)) {
                SerialPortManager.getInstance().setSpeedSlop(MotionDataUtils.getInstance().getCurrentInfo().speed, slop);
            } else {
                SerialPortManager.getInstance().setResistanceSlop(slop, MotionDataUtils.getInstance().getCurrentInfo().slop);
            }
        }
    }

    public void concealButton(){
        closeConcealButton();
        concealButtonDisposable = Observable.timer(countDownConcealButton, TimeUnit.SECONDS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Long>() {
                    @Override
                    public void accept(Long aLong) throws Exception {
                        clHome.setVisibility(View.INVISIBLE);
                        setViewGone(R.id.line);
                        closeConcealButton();
                    }
                });

    }

    public void closeConcealButton(){
        if(concealButtonDisposable != null){
            concealButtonDisposable.dispose();
            concealButtonDisposable = null;
        }
    }

    @Override
    public void getVideoCourseDetailSuccess(VideoBean detail) {
        if (isFinish() || detail == null) {
            return;
        }
        mDuration = detail.getAlltime();
        if (DataManager.Companion.getInstance().isLogin()) {
            ((VideoCourseDetailContract.Presenter) getPresenter()).addVideoRecord(mVideo.getVideoId());
        }
//        getNiceVideoPlayer().setUp("http" + Objects.requireNonNull(detail.getUrl()).substring(5), null);
        getNiceVideoPlayer().setUrl(detail.getUrl());
        vburst = detail.getVburst();
        getMultiProgressView().initData(mDuration, vburst);
        if(!mIsStart){
            mIsStart = true;
            getNiceVideoPlayer().start();
        }
    }

    @Override
    public void getLiveVideoDetailSuccess(VideoBean detail) {

    }

    @Override
    public void addcollectSuccess() {

    }

    @Override
    public void onResume() {
        super.onResume();
        ShowSpeedViewUtils.getInstance().initView(getApplicationContext());
        SportsStatusBarViewUtils.getInstance().initView(getApplicationContext());
        SportsStatusBarViewUtils.getInstance().isPlayVideo(true);
        if(mIsStart){
//            getNiceVideoPlayer().continueFromLastPosition(true);
            getNiceVideoPlayer().start();
//            resetInfo(BluetoothOrder.getInstance().getCurrentInfo());
        }
        SportsStatusBarViewUtils.getInstance().setHomeView(false);
        rlMain.setBackgroundResource(ThemeUtils.getInstance().getMainTheme());
    }

    @Override
    protected void onStop() {
        super.onStop();
        getNiceVideoPlayer().pause();

    }

    public void onDestroy() {
        super.onDestroy();
        closeConcealButton();
//        getNiceVideoPlayer().continueFromLastPosition(false);
        SportsStatusBarViewUtils.getInstance().isPlayVideo(false);
        NiceVideoPlayerManager.instance().releaseNiceVideoPlayer();
        ShowSpeedViewUtils.getInstance().goneLayout();
    }

    private VideoView getNiceVideoPlayer() {
        if (mNiceVideoPlayer == null) {
            mNiceVideoPlayer = findViewById(R.id.videoView);
        }
        return mNiceVideoPlayer;
    }

    private MultiProgressView getMultiProgressView() {
        if (mMultiProgressView == null) {
            mMultiProgressView = findViewById(R.id.multiProgressView);
        }
        return mMultiProgressView;
    }


    private void resetSpeed(boolean isAdd) {
        if(!DeviceTypeUtils.isConnect()){
            showToast(R.string.app_device_connect);
            return;
        }
        BigDecimal speed = new BigDecimal(getTextById(R.id.tvSpeed));
        if (isAdd) {
            speed = speed.add(new BigDecimal("0.1"));
        } else {
            speed = speed.subtract(new BigDecimal("0.1"));
        }
        if (speed.compareTo(BigDecimal.ZERO) < 0) {
            return;
        }
        int slop = MotionDataUtils.getInstance().getCurrentInfo().slop;
        if(DeviceTypeUtils.connectDeviceType() == 0){
            BluetoothOrder.getInstance().setNowelAndSlope(speed.multiply(BigDecimal.TEN).intValue(),slop);
        }else {
            SerialPortManager.getInstance().setSpeedSlop(speed.multiply(BigDecimal.TEN).intValue(), slop);
        }
    }

    private void resetSlop(boolean isAdd) {
        if(!DeviceTypeUtils.isConnect()){
            showToast(R.string.app_device_connect);
            return;
        }
        BigDecimal value = new BigDecimal(getTextById(R.id.tvSlope));
        if (isAdd) {
            value = value.add(new BigDecimal("1"));
        } else {
            value = value.subtract(new BigDecimal("1"));
        }
        if (value.compareTo(BigDecimal.ZERO) < 0) {
            return;
        }
        if(DeviceTypeUtils.connectDeviceType() == 0){
            if (MotionDataUtils.mCurrentDeviceType.equals(DeviceTypeUtils.TREADMILL)){
                if (value.intValue() < 0) {
                    return;
                }
                int speed = MotionDataUtils.getInstance().getCurrentInfo().speed;
                BluetoothOrder.getInstance().setNowelAndSlope(speed,value.intValue());

            }else {

                if (value.intValue() < 0 || value.intValue() > 32) {
                    return;
                }
                int slop = MotionDataUtils.getInstance().getCurrentInfo().slop;
                BluetoothOrder.getInstance().setNowelAndSlope(value.intValue(), slop);
            }
        }else {
            if (MotionDataUtils.mCurrentDeviceType.equals(DeviceTypeUtils.TREADMILL)) {
                if (value.intValue() < 0) {
                    return;
                }
                int speed = MotionDataUtils.getInstance().getCurrentInfo().speed;
                SerialPortManager.getInstance().setSpeedSlop(speed, value.intValue());
            } else {
                if (value.intValue() < 0 || value.intValue() > 32) {
                    return;
                }
                int slop = MotionDataUtils.getInstance().getCurrentInfo().slop;
                SerialPortManager.getInstance().setResistanceSlop(value.intValue(), slop);
            }
        }
    }

    int time = -1;
    int currentStartTime = -1;
    int currentEndTime = -1;
    @Override
    public void onReceive(HashMap<String, Object> map) {
        if (map == null) {
            return;
        }
        super.onReceive(map);
        if (map.containsKey(EventBusEvent.TIME_CHANGE)) {
            if (mDuration <= 0) {
                return;
            }
            int current = (int) (getNiceVideoPlayer().getCurrentPosition() / 1000);
            if (mLastTime == current) {
                return;
            }
            resetTimeUI(mDuration, current);
            getMultiProgressView().setProgress(current);
//            setSpeedAndSlop(current);

        }else if(map.containsKey(EventBusEvent.KILL_ACTIVITY)){
//            HashMap<String, Object> map1 = new HashMap<>();
//            map1.put(EventBusEvent.STOP_RUN,"");
//            EventBus.getDefault().post(map1);
            finish();
        }else if(map.containsKey(EventBusEvent.PAUSE_RUN)){
//                showStartBtn(false);
//                ShowSpeedViewUtils.getInstance().goneLayout();
//                SportsStatusBarViewUtils.getInstance().showStartBtn(false);
            mIsStart = false;
//                getNiceVideoPlayer().continueFromLastPosition(false);
            getNiceVideoPlayer().pause();
            time = 1;

        }else if(map.containsKey(EventBusEvent.START_RUN)){
            getNiceVideoPlayer().start();
            mIsStart = true;
        }else if(map.containsKey(EventBusEvent.SAFETY_LOCK)){
//            boolean b = (boolean) map.get(EventBusEvent.SAFETY_LOCK);
            getNiceVideoPlayer().pause();
        }

    }

    @Override
    public void resetInfo(SerialPortManager.CurrentInfo info) {
//        super.resetInfo(info);
        if(!(DeviceTypeUtils.getDeviceType() == 2)){
            setSpeedAndSlop(info);
        }
        if (mDuration <= 0) {
            return;
        }
        int current = (int) (getNiceVideoPlayer().getCurrentPosition() / 1000);
        if (mLastTime == current) {
            return;
        }
        resetTimeUI(mDuration, current);
        getMultiProgressView().setProgress(current);
    }

    /**
     * 设置视频播放节点的速度和坡度
     */
    public void setSpeedAndSlop(SerialPortManager.CurrentInfo info){
        if(info.time > time){//TODO 当前时间计算会有几毫秒的差值，会导致秒数回退
            System.out.println("ddddddddddddddddddddddd  current 11111   : "+getNiceVideoPlayer().getCurrentPosition());
            System.out.println("ddddddddddddddddddddddd  current : "+info.toString());
            time = info.time;
            for (VideoSectionBean videoSectionBean : vburst){
                if(time > videoSectionBean.getStartime() && time <= videoSectionBean.getEndtime()){
                    if(currentStartTime != videoSectionBean.getStartime() &&currentEndTime != videoSectionBean.getEndtime()){
                        currentStartTime = videoSectionBean.getStartime();
                        currentEndTime = videoSectionBean.getStartime();
                        int speed = (int) (videoSectionBean.getSpeed()*10);
                        int drag = videoSectionBean.getDrag();
                        if((videoSectionBean.getEndtime() - time) <= 5){

                        }else {

                        }

                        if(DeviceTypeUtils.getInstance().isTreadmill()){
                            if(info.speed == speed && info.slop == drag){
                                return;
                            }
                        }else {
                            if(info.slop == drag){
                                return;
                            }
                        }

                        if(DeviceTypeUtils.isConnect()){
                            if(DeviceTypeUtils.getInstance().isTreadmill()){
                                if(DeviceTypeUtils.connectDeviceType() == 0){
                                    BluetoothOrder.getInstance().setTreadmillSpeedAndSlope(speed,drag);
                                }else {
                                    SerialPortManager.getInstance().setSpeedSlop(speed,drag);
                                }

                            }else {
                                if(DeviceTypeUtils.connectDeviceType() == 0){
                                    BluetoothOrder.getInstance().setNowelAndSlope(drag,speed);
                                }else{
                                    SerialPortManager.getInstance().setResistanceSlop(drag,speed);

                                }

                            }
                        }else {
                            ToastUtils.showShort(getString(R.string.app_device_connect));
                        }

                        System.out.println("ddddddddddddddddddddddd  currentVideoSectionBean : "+videoSectionBean.toString());
                    }
                    break;
                }
            }
            System.out.println("ddddddddddddddddddddddd  time : "+time);
        }
    }

    private void resetTimeUI(final int duration, final int current) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mLastTime = current;
                int dTime = duration - current;
                if (dTime > 0) {
                    int hour = dTime / 3600;
                    int minute = (dTime / 60) % 60;
                    int second = dTime % 60;
                    if (hour > 0) {
                        setText(R.id.tvRemainingTime, BaseUtils.StaticParams.getNewText(hour) + ":"
                                + BaseUtils.StaticParams.getNewText(minute) + ":"
                                + BaseUtils.StaticParams.getNewText(second));
                    } else {
                        setText(R.id.tvRemainingTime, BaseUtils.StaticParams.getNewText(minute) + ":"
                                + BaseUtils.StaticParams.getNewText(second));
                    }
                }
            }
        });
    }


    public void showStartBtn(boolean isRun) {
        super.showStartBtn(isRun);
        if (isRun) {
            setViewGone(R.id.iv);
            if (mIsInit) {
                getNiceVideoPlayer().start();
                mIsInit = false;
            } else {
                getNiceVideoPlayer().start();
            }
        } else {
            NiceVideoPlayerManager.instance().releaseNiceVideoPlayer();
            mIsInit = true;
        }
    }

    /**
     * 停止初始化控件
     */
    public void initWidget(){
        setText(R.id.tvSlope, "0");
        setText(R.id.tvDistance, "0");
        setText(R.id.tvTime, "00:00");
        setText(R.id.tvSpeed, "0.00");
        if(DeviceTypeUtils.connectDeviceType() == 0){
            BluetoothOrder.getInstance().closeCurrentInfo();
        }else {
            SerialPortManager.getInstance().closeCurrentInfo();
        }
    }


    public void setViewsAlpha(float alpha, int... viewIds) {

    }

    @Override
    public boolean isMainActivity() {
        return false;
    }


//    private void resetSpeedBtn(int index) {
//        for (int i = 1; i < 5; ++i) {
//            int id = getResources().getIdentifier("llSpeed" + i, "id", getPackageName());
//            LinearLayout llSpeed = findViewById(id);
//            if (i == index) {
//                llSpeed.setBackgroundResource(R.drawable.shape_ffffff_tr_br_3);
//                ((TextView) llSpeed.getChildAt(0)).setTextColor(ContextCompat.getColor(this, com.common.lib.R.color.color_2d_2c_2f));
//                ((TextView) llSpeed.getChildAt(1)).setTextColor(ContextCompat.getColor(this, com.common.lib.R.color.color_2d_2c_2f));
//            } else {
//                llSpeed.setBackgroundResource(mMainStyle == 3 ? R.drawable.shape_2bffffff_tr_br_3 : R.drawable.shape_2d2c2f_tr_br_3);
//                ((TextView) llSpeed.getChildAt(0)).setTextColor(ContextCompat.getColor(this, com.common.lib.R.color.text_color_1));
//                ((TextView) llSpeed.getChildAt(1)).setTextColor(ContextCompat.getColor(this, com.common.lib.R.color.text_color_1));
//            }
//        }
//    }

//    private void resetSlopBtn(int index) {
//        for (int i = 1; i < 5; ++i) {
//            int id = getResources().getIdentifier("llSlop" + i, "id", getPackageName());
//            LinearLayout llSlop = findViewById(id);
//            if (i == index) {
//                llSlop.setBackgroundResource(R.drawable.shape_ffffff_tr_br_3);
//                ((TextView) llSlop.getChildAt(0)).setTextColor(ContextCompat.getColor(this, com.common.lib.R.color.color_2d_2c_2f));
//                ((TextView) llSlop.getChildAt(1)).setTextColor(ContextCompat.getColor(this, com.common.lib.R.color.color_2d_2c_2f));
//            } else {
//                llSlop.setBackgroundResource(mMainStyle == 3 ? R.drawable.shape_2bffffff_tr_br_3 : R.drawable.shape_2d2c2f_tr_br_3);
//                ((TextView) llSlop.getChildAt(0)).setTextColor(ContextCompat.getColor(this, com.common.lib.R.color.text_color_1));
//                ((TextView) llSlop.getChildAt(1)).setTextColor(ContextCompat.getColor(this, com.common.lib.R.color.text_color_1));
//            }
//        }
//    }

}